﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Cci;
using Microsoft.Cci.Ast;

namespace ReactiveLang.AssemblyRewriter
{
    class ReactiveErrorMessage: ErrorMessage
    {
        public ReactiveErrorMessage(ISourceLocation sourceLocation, Error error, params string[] messageArguments)
          : base(sourceLocation, (long)error, error.ToString(), messageArguments) {
        }
        private ReactiveErrorMessage(ISourceLocation sourceLocation, long errorCode, string messageKey, IEnumerable<ILocation> relatedLocations, string[] messageArguments)
          : base(sourceLocation, errorCode, messageKey, relatedLocations, messageArguments) {
        }

        public override object ErrorReporter
        {
            get { return SemanticErrorReporter.Instance; }
        }

        public override string ErrorReporterIdentifier
        {
            get { return "Rulez"; }
        }

        public override ISourceErrorMessage MakeShallowCopy(ISourceDocument targetDocument)
        {
            if (this.SourceLocation.SourceDocument == targetDocument) 
                return this;
            return new ReactiveErrorMessage(targetDocument.GetCorrespondingSourceLocation(this.SourceLocation), 
                this.Code, this.MessageKey, this.RelatedLocations, this.MessageArguments());
        }

        public override string Message
        {
            get 
            {
                System.Resources.ResourceManager rmgr = new System.Resources.ResourceManager(typeof(ErrorMessages).FullName, typeof(ErrorMessages).Assembly);
                return this.GetMessage(rmgr);
            }
        }

        public override string ToString()
        {
           // var primarySourceLocation = SourceLocation as IPrimarySourceLocation;
           // string address = primarySourceLocation != null ? 

           //return string.Format("{0}({1},{2}): {3}: {4}",
           //    this.SourceLocation.Document.Name.Value,
           //    this.SourceLocation.
           //    ) 
            return base.ToString();
        }
    }
}
